package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.adapter.DealerWaitCheckAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.base.BaseWaitCheckFragment;
import com.bjesc_b2c.app.appraiset.bean.WaitCheckCarBean;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.AnomalyFragment;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.WaitDetectionFragment;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
import com.rxretrofit_build.model.RxBusBean;
import com.rxretrofit_build.util.MapUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import rxretrofit_base.model.KeyBean;

/**
 * Created by yidong on 2017/8/2.
 */

public class DealerWaitCheckActivity extends BaseActivity  {
    //    @Bind(R.id.recycler_view)
//    RecyclerView carfromTwoRecycler;
    @Bind(R.id.tv_title)
    TextView titleTv;
    @Bind(R.id.iv_return)
    LinearLayout returnLin;
    private DealerWaitCheckAdapter mAdapter;
    private List<WaitCheckCarBean.CarsBean> carForBean;
    private String dealerId;
    private LinearLayoutManager twoManager;

    @Bind(R.id.viewpager)
    ViewPager mViewPager;
    @Bind(R.id.viewpager_tab)
    SmartTabLayout mViewpagerTab;
    @Bind(R.id.title_view)
    View titleView;
    @Bind(R.id.tv_car_name_title)
    TextView nameTv;
    @Bind(R.id.edit_search_name)
    EditText searchEdit;
    @Bind(R.id.input_title)
    RelativeLayout relativeLayout;

    @Override
    protected int getLayout() {
        return R.layout.activity_await_task;
    }

    @Override
    protected void initEventAndData() {
        relativeLayout.setVisibility(View.GONE);
        titleView.setVisibility(View.GONE);
        titleTv.setText(getIntent().getStringExtra("Title"));
        returnLin.setVisibility(View.VISIBLE);
        String marketID = getIntent().getStringExtra("marketId");
        CustomSharedPreferences.saveString(mContext, new MapUtil()
                .put(KeyBean.MARKET_ID.valueOf(), marketID)
                .build(), KeyBean.FILE_NAME.valueOf());
        final LayoutInflater inflater = LayoutInflater.from(this);
        final int[] tabTitles = {R.string.wait_collection, R.string.anomaly};
        FragmentPagerItems pages = FragmentPagerItems.with(this)
                .add(R.string.wait_collection, WaitDetectionFragment.class)
                .add(R.string.anomaly, AnomalyFragment.class)
                .create();
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);
        mViewPager.setOffscreenPageLimit(pages.size());
        mViewPager.setAdapter(adapter);
        mViewpagerTab.setCustomTabView(new SmartTabLayout.TabProvider() {
            @Override
            public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
                View view = inflater.inflate(R.layout.layout_navigation_top_item, container, false);
                TextView titleView = (TextView) view.findViewById(R.id.txt_title);
                titleView.setText(tabTitles[position % tabTitles.length]);
                return view;
            }
        });
        mViewpagerTab.setViewPager(mViewPager);
    }

    @Override
    protected void createPresenter() {
//        requestCarMarket(this, dealer_id);
    }

    @OnClick(R.id.iv_return)
    public void onClick() {
        finish();
    }

    @Override
    protected void doOnNext(RxBusBean rxBusBean) {
        super.doOnNext(rxBusBean);
        if (rxBusBean.getRequestMark().equals(BaseWaitCheckFragment.class.getName())){
            if (rxBusBean.getO() instanceof WaitCheckCarBean.CountBean){
                WaitCheckCarBean.CountBean bean = (WaitCheckCarBean.CountBean)rxBusBean.getO();
                TextView textView_1 = (TextView) mViewpagerTab.getTabAt(0).findViewById(R.id.txt_number);
                textView_1.setText(bean.getExamine_count()+"");
                TextView textView_2 = (TextView) mViewpagerTab.getTabAt(1).findViewById(R.id.txt_number);
                textView_2.setText(bean.getUnusual_count()+"");
            }
        }
    }
}
